Skip to content

[CI] (3f39e0e) fastapi/fastapi3-ai-saas - #4155

Closed
wizard-ci-bot[bot] wants to merge 1 commit into
mainfrom
wizard-ci-3f39e0e-fastapi-fastapi3-ai-saas
Closed

wizard-ci-bot[bot] wants to merge 1 commit into
mainfrom
wizard-ci-3f39e0e-fastapi-fastapi3-ai-saas

Conversation

@wizard-ci-bot

@wizard-ci-bot wizard-ci-bot Bot commented Sep 23, 2026

Copy link
Copy Markdown

Automated wizard CI run

Source: wizard-pr
Trigger ID: 3f39e0e
App: fastapi/fastapi3-ai-saas
App directory: apps/fastapi/fastapi3-ai-saas
Workbench branch: wizard-ci-3f39e0e-fastapi-fastapi3-ai-saas
Wizard branch: release-please--branches--main--components--wizard
Context Mill branch: main
PostHog (MCP) branch: master
Timestamp: 2026-09-23T21:57:26.646Z
Duration: 572.9s

YARA Scanner

✓ 192 tool calls scanned, 0 violations detected

No violations: ✓ 192 clean scans

@wizard-ci-bot

wizard-ci-bot Bot commented Sep 23, 2026

Copy link
Copy Markdown
Author

PR Evaluation Report

Summary

This PR integrates PostHog into a FastAPI AI SaaS application by adding the Python SDK with instance-based initialization in the lifespan handler, a custom ASGI middleware for user identity context, event captures across auth/generation/settings/API-key routes, error tracking via exception handler and autocapture, and an OpenTelemetry log exporter for structured logging to PostHog.

Files changed Lines added Lines removed
10 +232 -6

Confidence score: 5/5 🧙

  • RuntimeError on missing env vars in debug mode: In the lifespan, when debug=True and PostHog env vars are missing, a RuntimeError is raised which crashes the app on startup. This is overly aggressive — a warning log would be more appropriate since PostHog is an analytics addon, not a core dependency. [MEDIUM]
  • Synchronous DB access in async middleware: PostHogMiddleware._get_authenticated_user() performs a synchronous SQLAlchemy query inside an async ASGI middleware, which blocks the event loop on every request. This should use an async DB session or run in a thread executor. [MEDIUM]

File changes

Filename Score Description
.env.example 5/5 Adds POSTHOG_PROJECT_TOKEN and POSTHOG_HOST placeholders
app/config.py 5/5 Adds PostHog settings fields to Pydantic Settings class
app/main.py 4/5 Initializes PostHog client in lifespan, adds error handler capture, registers shutdown with atexit
app/middleware.py 3/5 Custom ASGI middleware for PostHog context; synchronous DB call blocks event loop
app/posthog_logs.py 4/5 New file for OpenTelemetry log export to PostHog — works but adds significant dependency overhead
app/routers/api_keys.py 4/5 Captures api_key_created and api_key_revoked events
app/routers/auth.py 5/5 Captures signup/login/logout with proper identify and person properties
app/routers/generate.py 4/5 Captures content_generated event with properties; also logs via OTel
app/routers/settings.py 5/5 Captures email_updated and password_changed; updates person properties
requirements.txt 4/5 Adds posthog and OpenTelemetry packages with pinned versions

App sanity check ⚠️

Criteria Result Description
App builds and runs Yes All imports resolve, dependencies added, no syntax errors
Preserves existing env vars & configs Yes Existing env vars and configs unchanged; PostHog additions are additive
No syntax or type errors Yes Code is syntactically valid Python
Correct imports/exports Yes All imports are correct — posthog.Posthog, OTel packages, internal modules
Minimal, focused changes Yes All changes relate to PostHog integration
Pre-existing issues None

Issues

  • Synchronous DB in async middleware: _get_authenticated_user() calls SessionLocal() and User.get_by_id() synchronously, blocking the asyncio event loop on every HTTP request. Should use run_in_executor or an async session. [MEDIUM]
  • RuntimeError on missing config in debug mode: Raising RuntimeError in the lifespan when PostHog env vars are missing crashes the entire app in debug mode. A warning log would be safer. [MEDIUM]

Other completed criteria

  • Environment variables properly documented in .env.example
  • Build configuration valid with pinned dependency versions
  • All changes are relevant to PostHog integration
  • Code follows existing codebase patterns (guard patterns, router structure)

PostHog implementation ⚠️

Criteria Result Description
PostHog SDKs installed Yes posthog==7.60.0 added to requirements.txt
PostHog client initialized Yes Instance-based Posthog() constructor in lifespan with enable_exception_autocapture=True
capture() Yes Multiple meaningful capture calls across auth, generation, settings, and API key routes
identify() N/A Server-only app
Error tracking Yes enable_exception_autocapture=True plus manual capture_exception() in 500 handler
Reverse proxy N/A Server-only app

Issues

  • No flush() before shutdown() needed — but atexit + lifespan double-shutdown: The client is shut down both via atexit.register(posthog_client.shutdown) and in the lifespan teardown. The second shutdown() call on an already-shut-down client may log warnings or behave unexpectedly. The atexit registration is a good safety net, but calling shutdown() twice is not ideal. [LOW]

Other completed criteria

  • API key loaded from environment variable via Pydantic Settings (posthog_project_token)
  • Host correctly configured from environment variable (posthog_host)
  • Screen views: N/A (server-only)
  • All targets initialized: N/A (single-target)
  • User identification done correctly via identify_context() in middleware with str(user.id) as distinct_id
  • Person properties set via posthog_client.set() with email in identify_authenticated_user and settings update

PostHog insights and events ✅

Filename PostHog events Description
app/routers/auth.py user_logged_in, user_signed_up, user_logged_out Core auth funnel with login method and signup method properties
app/routers/generate.py content_generated Core product action with generation_type, credits_used, prompt_length
app/routers/api_keys.py api_key_created, api_key_revoked API key lifecycle with active_key_count
app/routers/settings.py email_updated, password_changed Account settings changes
app/main.py capturedException 500 error handler captures exceptions with user context

Issues

No issues.

Other completed criteria

  • Events represent real user actions mapping to actual product flows
  • Events enable product insights — signup→login→generate funnel is clearly buildable
  • Events include relevant contextual properties (generation_type, credits_used, login_method, etc.)
  • No PII in event properties — email is set via posthog_client.set() as person property, not in capture properties
  • Event names are descriptive, consistent snake_case convention

Reviewed by wizard workbench PR evaluator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants